#ifndef MINESWEEPER_HPP_INCLUDED
#define MINESWEEPER_HPP_INCLUDED

#include <SFML/Graphics.hpp>

#include <list>

#include "../game_state.hpp"
#include "../singleton.hpp"

enum Tile {
	Sand = 0,
	One,
	Two,
	Three,
	Four,
	Five,
	Six,
	Seven,
	Eight,
	Water,
	HiddenMine,
	ExplodedMine
};

struct Sweeper {
	int x, y;
	sf::Sprite target;
};

class MineSweeper: public GameState, public Singleton<MineSweeper> {
	friend class Singleton<MineSweeper>;
	public:
		void init(Engine *engine);
		void cleanup();
		
		void pause();
		void resume();
		
		void processEvent(Engine *engine, PlayerEvent& event);
		void update(Engine *engine);
		void draw(Engine *engine);
		
		sf::Sprite tileSprite;
		
		Tile tiles[400];
		int flags[400];
		
		std::map<int, Sweeper> sweepers;
		std::list<ScoreString> scoreStrings;
		
		sf::Clock clock;
		//float lastTime;
		
	protected:
		bool tileFree(int x, int y);
		bool hasMine(int x, int y);
		bool hasFlag(int x, int y);
		int countMines(int x, int y);
		void recurse(int x, int y);
		
		void bang(Engine *engine, int index);
		void flag(Engine *engine, int index);
		void addScore(Engine *engine, int player, int score);
		
		MineSweeper();
		~MineSweeper();
};

#endif // MINESWEEPER_HPP_INCLUDED
